package com.zzty.train.serviceImpl;


import com.alibaba.fastjson.JSONObject;
import com.zzty.train.entity.Clazz;
import com.zzty.train.entity.User;
import com.zzty.train.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.zzty.train.util.HttpUtil.httpGet;
import static com.zzty.train.util.HttpUtil.httpPostWithJSON;


@Service
public class UserServiceImpl implements UserService {
    @Value("${checkUserName}")
    String url;
    @Override
    public User getUser(User user){
        System.out.println("start");
        String us=null;
        try {
            us = httpGet(url+"/"+user.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
        User user1=JSONObject.parseObject(us,User.class);
        System.out.println("userService"+user1);
        return user1;
    }


    @Value("${addUser}")
    String url1;
    @Override
    public Integer addUser(User user){
        String us=null;
        try {
            us = httpPostWithJSON(url1,user.toJsonString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        Integer count=JSONObject.parseObject(us,Integer.class);
        System.out.println("userService"+count);
        return count;
    }

    @Value("${getUserByName}")
    String url2;
    @Override
    public User getUserByName(User user){
        System.out.println("user"+user.toString());
        String us=null;
        try {
            us = httpPostWithJSON(url2,user.toJsonString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        User user1=JSONObject.parseObject(us,User.class);
        System.out.println("userService"+user1);
        return user1;
    }
}
